import Vue from "vue";
import Router from "vue-router";
import { Message } from "element-ui";
Vue.use(Router);

const router = new Router({
  mode: 'history',
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: () => import('@/views/LoginView') },
    {
      path: '/main', name: '主页', redirect: '/home', component: () => import('@/layout/MainView'),
      children: [
        { path: '/good', name: '商品', component: () => import('@/views/GoodView') },
        { path: '/home', name: '主页展示', component: () => import('@/views/HomeView') },
        { path: '/order', name: '订单', component: () => import('@/views/OrderView') },
        { path: '/permissonV', name: '权限', component: () => import('@/views/PermissonView') },
        { path: '/permissonC', name: '修改权限', component: () => import('@/views/PermissonChange') },
        { path: '/setting', name: '爸爸', component: () => import('@/views/SettingView') },
      ]
    },

  ]
})
// router.beforeEach((to, from, next) => {
//   //需要授权的路由地址
//   // console.log(to);
//   let arrPath = ['/main', '/permissonC', '/home']
//   let isAuth = arrPath.some(item => {return to.path.startsWith(item)})
//   if (!isAuth) {
//     next();
//     return
//   }
//   let token = sessionStorage.getItem('token');
//   if (token) {
//     next();
//   } else {
//     Message.warning('请先登录')
//     next('/login')
//   }

// })
export default router